package cn.edu.cqupt.cxcy.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.cqupt.cxcy.dao.AdminDao;
import cn.edu.cqupt.cxcy.dto.AdminImpl;
import cn.edu.cqupt.cxcy.model.Investor;
import cn.edu.cqupt.cxcy.model.Team;
import cn.edu.cqupt.cxcy.util.JsonUtil;
import cn.edu.cqupt.cxcy.util.Validate;


/**
 * 主页-【场地预约】
 * @author Dancer-mno
 * @date 2015年10月17日
 */
@SuppressWarnings("serial")
public class AdminAjaxSeekInfo extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		String type = req.getParameter("type"); //类别
		int id = Validate.stringIsNO(req.getParameter("id"))?Integer.parseInt(req.getParameter("id")) : 0; //类别
		AdminDao admin = new AdminImpl();
		JsonUtil json = new JsonUtil(); 
		List<Object> lists = null;
		// 主url  /admin/seekInfo
		// 投资人  /admin/seekInfo?type=inve&&id=? 返回投资人的信息以及投资项目
		// 项目      /admin/seekInfo?type=proj&&id=? 返回该项目的信息
		// 团队      /admin/seekInfo?type=team&&id=? 返回团队信息以及队员名单
		// 导师       /admin/seekInfo?type=teac&&id=? 返回教师信息以及导师指导的团队()
		// 新闻       /admin/seekInfo?type=news&&id=? 返回新闻信息
		if("inve".equals(type)) {
			Investor inve = admin.invenfo(id);
			lists = admin.invePro(id);
			json.put("inve", inve);
			json.put( "invePro", lists);
		} else if("proj".equals(type)) {
			lists = admin.proInfo(id);
			json.put("proInfo", lists);
		} else if("team".equals(type)) {
			Team team  = admin.teamInfo(id);
			lists = admin.memberInfo(id);
			json.put("team", team);
			json.put("memberList", lists);
		} else if("teac".equals(type)) {
			List<Object> tutor  = admin.tutorInfo(id);
			lists = admin.tutorTeam(id);
			json.put("tutor", tutor);
			json.put("tutorTeam", lists);
		} else if("news".equals(type)) {
			lists = admin.newsInfo(id);
			json.put("newsInfo", lists);
		}
		resp.setContentType("application/json;charset=utf-8");
		resp.setHeader("pragma","no-cache");
		resp.setHeader("cache-control","no-cache");
		PrintWriter out = resp.getWriter();
		out.print(json);
		out.flush();
		out.close();
	}


}
